# 1、先写出业务
# 2、改造成函数
# 3、函数的4种写法全部实现


# 作业：输入年、月、日。判断今天是整年的第几天
# 2020-4-19     2020：闰年---2月29   31+29+31  月：4  1+2+3  日：19
# 结果：31+29+31+19   2020 04 19    2020-04-19
# str = '2020-04-19'
# data= str.split('-')
# print(data)

def total_day(year, month, day):
    data = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    result = 0

    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        data[1] = 29

    for i in range(month - 1):
        result = result + data[i]

    total = result + day
    return total


total = total_day(2020, 4, 19)
print(f'总天数为：{total}')



def total_day2(date):
    year=int(date.split('-')[0])
    month = int(date.split('-')[1])
    day = int(date.split('-')[2])

    data = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    result = 0

    if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
        data[1] = 29

    for i in range(month - 1):
        result = result + data[i]

    total = result + day
    return total

total = total_day2('2020-04-19')
print(f'总天数为：{total}')
